Skip to content

fix: parameterize schema and publication name in postgres-cdc-demo init SQL#1

Merged
sfc-gh-pvillard merged 1 commit into
mainfrom
fix/parameterize-postgres-cdc-demo
May 24, 2026
Merged

fix: parameterize schema and publication name in postgres-cdc-demo init SQL#1
sfc-gh-pvillard merged 1 commit into
mainfrom
fix/parameterize-postgres-cdc-demo

Conversation

@sfc-gh-pvillard
Copy link
Copy Markdown
Collaborator

Summary

  • Add Publication Name parameter (default: demo_publication) to the flow's parameter context
  • Replace hardcoded demo_postgres schema in the init SQL with #{Schema Name}
  • Replace hardcoded demo_publication in the init SQL with #{Publication Name}
  • Update documentation to include the new parameter

This ensures the flow is fully portable — any deployment can configure its own schema and publication name rather than being forced to use hardcoded values.

Test plan

  • Import flow and verify Publication Name parameter appears in NiFi
  • Verify init SQL creates schema and publication using the configured parameter values

.... Generated with Cortex Code

…it SQL

- Add Publication Name parameter (default: demo_publication)
- Replace hardcoded demo_postgres schema with #{Schema Name} in init SQL
- Replace hardcoded demo_publication with #{Publication Name} in init SQL
- Update documentation to include Publication Name parameter

.... Generated with [Cortex Code](https://docs.snowflake.com/en/user-guide/cortex-code/cortex-code)

Co-Authored-By: Cortex Code <noreply@snowflake.com>
@github-actions
Copy link
Copy Markdown

🚀 Flow Deploy Available

This PR modifies flow definitions that have a CI test configuration. A maintainer (admin or maintain permission) can deploy and test the flow on an ephemeral Snowflake runtime by commenting:

deploy this flow or deploy the flow

This will:

  1. Create a dedicated ephemeral runtime
  2. Deploy the changed flow(s)
  3. Run validation tests
  4. Tear down the runtime and report results

To keep the runtime alive for debugging, add do not clean to the comment.

@github-actions github-actions Bot added documentation Improvements or additions to documentation flows labels May 23, 2026
@github-actions
Copy link
Copy Markdown

Note

This GitHub Action is created and maintained by Snowflake.

Identified 1 changed flows in this Pull Request.

Executing Snowflake Flow Diff for flow: postgres-cdc-demo

No Checkstyle Violations found

Flow Changes

  • In Processor of type ExecuteSQLStatement named ExecuteSQLStatement, the value of the property SQL changed from
CREATE SCHEMA IF NOT EXISTS demo_postgres;

CREATE TABLE IF NOT EXISTS demo_postgres.customers (
    customer_id INTEGER PRIMARY KEY,
    first_name VARCHAR(100) NOT NULL,
    last_name VARCHAR(100) NOT NULL,
    email VARCHAR(255),
    phone VARCHAR(50),
    updated_at TIMESTAMP DEFAULT NOW()
);

CREATE TABLE IF NOT EXISTS demo_postgres.orders (
    order_id INTEGER PRIMARY KEY,
    customer_id INTEGER NOT NULL,
    order_status VARCHAR(50) DEFAULT 'pending',
    total_amount NUMERIC(10,2),
    shipping_address TEXT,
    updated_at TIMESTAMP DEFAULT NOW()
);

CREATE TABLE IF NOT EXISTS demo_postgres.order_items (
    item_id SERIAL PRIMARY KEY,
    order_id INTEGER NOT NULL,
    product_name VARCHAR(255) NOT NULL,
    quantity INTEGER DEFAULT 1,
    unit_price NUMERIC(10,2)
);

DO $$
BEGIN
    IF NOT EXISTS (SELECT 1 FROM pg_publication WHERE pubname = 'demo_publication') THEN
        CREATE PUBLICATION demo_publication FOR TABLE
            demo_postgres.customers,
            demo_postgres.orders,
            demo_postgres.order_items;
    END IF;
END
$$;

to

CREATE SCHEMA IF NOT EXISTS #{Schema Name};

CREATE TABLE IF NOT EXISTS #{Schema Name}.customers (
    customer_id INTEGER PRIMARY KEY,
    first_name VARCHAR(100) NOT NULL,
    last_name VARCHAR(100) NOT NULL,
    email VARCHAR(255),
    phone VARCHAR(50),
    updated_at TIMESTAMP DEFAULT NOW()
);

CREATE TABLE IF NOT EXISTS #{Schema Name}.orders (
    order_id INTEGER PRIMARY KEY,
    customer_id INTEGER NOT NULL,
    order_status VARCHAR(50) DEFAULT 'pending',
    total_amount NUMERIC(10,2),
    shipping_address TEXT,
    updated_at TIMESTAMP DEFAULT NOW()
);

CREATE TABLE IF NOT EXISTS #{Schema Name}.order_items (
    item_id SERIAL PRIMARY KEY,
    order_id INTEGER NOT NULL,
    product_name VARCHAR(255) NOT NULL,
    quantity INTEGER DEFAULT 1,
    unit_price NUMERIC(10,2)
);

DO $$
BEGIN
    IF NOT EXISTS (SELECT 1 FROM pg_publication WHERE pubname = '#{Publication Name}') THEN
        CREATE PUBLICATION #{Publication Name} FOR TABLE
            #{Schema Name}.customers,
            #{Schema Name}.orders,
            #{Schema Name}.order_items;
    END IF;
END
$$;
  • In the Parameter Context CDC Postgres Demo - Data Generator a parameter has been added: Publication Name = demo_publication with the description Name of the PostgreSQL publication to create for CDC. Must match the publication name used by the CDC connector.

Copy link
Copy Markdown
Collaborator

@sfc-gh-dchaffelson sfc-gh-dchaffelson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Good improvement.

@sfc-gh-pvillard sfc-gh-pvillard merged commit e37ad20 into main May 24, 2026
4 checks passed
@sfc-gh-pvillard sfc-gh-pvillard deleted the fix/parameterize-postgres-cdc-demo branch May 24, 2026 09:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation flows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants